/*
 * Copyright (C) 2016  Nicola Spanti (RyDroid) <dev@nicola-spanti.info>
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */


#include <stdlib.h>
#include <check.h>
#include "PlanetWars2dRT-core/utils/color_rgb.h"


struct color_rgb color1, color2;


START_TEST(test_equals)
{
  color1.red = color1.green = color1.blue = 0;
  ck_assert(color_rgb_equals(color1, color1));
  
  color2 = color1;
  ck_assert(color_rgb_equals(color1, color2));
  
  color1 = color2;
  ++color1.red;
  ck_assert(!color_rgb_equals(color1, color2));
  
  color1 = color2;
  ++color1.green;
  ck_assert(!color_rgb_equals(color1, color2));
  
  color1 = color2;
  ++color1.blue;
  ck_assert(!color_rgb_equals(color1, color2));
  
  color1 = color2;
  COLOR_RGB_INVERSE(color1)
  ck_assert(!color_rgb_equals(color1, color2));
}
END_TEST

START_TEST(test_inverse)
{
  color1.red = color1.green = color1.blue =   0;
  color2.red = color2.green = color2.blue = 255;
  COLOR_RGB_INVERSE(color2);
  ck_assert(color_rgb_equals(color1, color2));
  COLOR_RGB_INVERSE(color2);
  ck_assert(!color_rgb_equals(color1, color2));
  
  color1.red = color1.green = color1.blue =   0;
  color2.red = color2.green = color2.blue = 255;
  color_rgb_inverse(&color2);
  ck_assert(color_rgb_equals(color1, color2));
  color_rgb_inverse(&color2);
  ck_assert(!color_rgb_equals(color1, color2));
  
  color1.red = color1.green = color1.blue =   0;
  color2.red = color2.green = color2.blue = 255;
  color2 = get_color_rgb_inversed(color2);
  ck_assert(color_rgb_equals(color1, color2));
  color2 = get_color_rgb_inversed(color2);
  ck_assert(!color_rgb_equals(color1, color2));
}
END_TEST

START_TEST(test_const_not_equals)
{
  ck_assert(!color_rgb_equals(COLOR_RGB_WHITE, COLOR_RGB_BLACK));
  ck_assert(!color_rgb_equals(COLOR_RGB_WHITE, COLOR_RGB_RED));
  ck_assert(!color_rgb_equals(COLOR_RGB_WHITE, COLOR_RGB_GREEN));
  ck_assert(!color_rgb_equals(COLOR_RGB_WHITE, COLOR_RGB_BLUE));
  ck_assert(!color_rgb_equals(COLOR_RGB_WHITE, COLOR_RGB_GRAY));
  
  ck_assert(!color_rgb_equals(COLOR_RGB_BLACK, COLOR_RGB_GRAY));
  ck_assert(!color_rgb_equals(COLOR_RGB_BLACK, COLOR_RGB_RED));
  ck_assert(!color_rgb_equals(COLOR_RGB_BLACK, COLOR_RGB_GREEN));
  ck_assert(!color_rgb_equals(COLOR_RGB_BLACK, COLOR_RGB_BLUE));
}
END_TEST

START_TEST(test_const_inverse)
{
  ck_assert(color_rgb_equals(COLOR_RGB_WHITE,
			     get_color_rgb_inversed(COLOR_RGB_BLACK)));
}
END_TEST


Suite*
color_rgb_suite(void)
{
  Suite* s = suite_create("Color");
  
  TCase* tc_core = tcase_create("Core");
  tcase_add_test(tc_core, test_equals);
  tcase_add_test(tc_core, test_inverse);
  suite_add_tcase(s, tc_core);
  
  TCase* tc_const = tcase_create("Const");
  tcase_add_test(tc_const, test_const_not_equals);
  tcase_add_test(tc_const, test_const_inverse);
  suite_add_tcase(s, tc_const);
  
  return s;
}

int
main(void)
{
  size_t number_failed;
  Suite* s;
  SRunner* sr;

  s = color_rgb_suite();
  sr = srunner_create(s);
  
  srunner_run_all(sr, CK_NORMAL);
  number_failed = srunner_ntests_failed(sr);
  srunner_free(sr);
  
  return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
}
